package com.qeeyou.apps.android.craftsman.activity.me;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

import com.qeeyou.apps.android.craftsman.R;
import com.qeeyou.apps.android.craftsman.adapter.HelpAdapter;
import com.qeeyou.apps.android.craftsman.po.HelpItemInfo;

import java.util.ArrayList;
import java.util.List;

public class HelpActivity extends Activity {

    private ImageView btnBack;
    private ListView lstvInfo;
    private HelpAdapter mAdapter;
    private List<HelpItemInfo> infoList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help);

        setView();

        setEvent();
    }

    private void setView() {
        btnBack = (ImageView) this.findViewById(R.id.btnBack4Help);
        lstvInfo = (ListView) this.findViewById(R.id.lstvInfo4Help);
    }

    private void setEvent() {
        testData();
        btnBack.setOnClickListener(onBackClickListener);
        mAdapter = new HelpAdapter(HelpActivity.this, infoList);
        lstvInfo.setAdapter(mAdapter);
        lstvInfo.setOnItemClickListener(onItemClickListener);
    }

    private View.OnClickListener onBackClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            HelpActivity.this.finish();
        }
    };

    private AdapterView.OnItemClickListener onItemClickListener = new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(HelpActivity.this, QuestionDetailActivity.class);
            HelpActivity.this.startActivity(intent);
        }
    };

    private void testData() {
        if(infoList == null) {
            infoList = new ArrayList<HelpItemInfo>();
        }
        infoList.clear();
        HelpItemInfo helpItemInfo1 = new HelpItemInfo();
        helpItemInfo1.setId("1");
        helpItemInfo1.setTitle("我发布的订单怎样支付费用?");
        infoList.add(helpItemInfo1);
        HelpItemInfo helpItemInfo2 = new HelpItemInfo();
        helpItemInfo2.setId("2");
        helpItemInfo2.setTitle("发布了没人接单怎么办?");
        infoList.add(helpItemInfo2);
        HelpItemInfo helpItemInfo3 = new HelpItemInfo();
        helpItemInfo3.setId("3");
        helpItemInfo3.setTitle("师傅做的不好我可以退款吗?");
        infoList.add(helpItemInfo3);
        HelpItemInfo helpItemInfo4 = new HelpItemInfo();
        helpItemInfo4.setId("4");
        helpItemInfo4.setTitle("APP卡顿怎么解决?");
        infoList.add(helpItemInfo4);
        HelpItemInfo helpItemInfo5 = new HelpItemInfo();
        helpItemInfo5.setId("5");
        helpItemInfo5.setTitle("提现的金额大概多久可以到账?");
        infoList.add(helpItemInfo5);
    }
}
